<%@ page pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<jsp:include page="common/header.jsp"></jsp:include>
<script type="text/javascript" src="${pageContext.request.contextPath}/views/js/libs/ajaxfileupload.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/ueditor/ueditor.all.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/ueditor/lang/zh-cn/zh-cn.js"></script>
<style>
.bloc .tab_edit{float:left;width:100%;border:2px solid #ccc;height:50px;margin-bottom:20px;margin-top:2px;}
.bloc .tab_edit li{float:left;width:24.9%;}
.bloc .tab_edit li:hover,.bloc .tab_edit li.current{background:#ccc;}
.bloc .tab_edit a{float:left;display:block;width:100%;text-align:center;border-right:2px solid #ccc;height:50px;text-decoration:none;color:#333 !important;font-size:16px;font-weight:bold;line-height:50px;}
.bloc .tab_edit a:hover{text-decoration:none !important;}
#twitterlist img{margin:13px !important;}
.input input{color:#333 !important;font-weight:normal !important;cursor:auto !important;text-shadow:none !important;}
.input input:hover{background:#fff !important;}
.picBox{
	    position: fixed;
	    width: 100%;
	    height: 100%;
	    left: 0;
	    top: 0;
	    z-index: 99999;
	    background: rgba(0,0,0, .6);
    }
    .picBox span{
    	position: absolute;
	    right: 40px;
	    top: 60px;
	    color: #fff;
	    font-size: 20px;
	    font-weight: bold;
    }
    .picBox .center_pic{
    	position: absolute;
    	top: 50%;
    	left: 50%;
    	z-index: 11;
    	margin-left: -375px;
    	margin-top: -180px;
    	text-align: center;
   	    vertical-align: middle;
    }
</style>
<input type="hidden" name="projectName" id="projectName" value="${pageContext.request.contextPath }"/>
<h1>
	<img src="${pageContext.request.contextPath}/views/images/icons/posts.png" alt="" /> 编辑商品
</h1>
<div class="bloc">
	<div id="fadecon">
	<div class="submit">
		<div class="content">
			<form:form  commandName="modle" modelAttribute="model" action="${pageContext.request.contextPath}/admin-gftgoods/saveorupdate" onsubmit="return checkForm();" method="post" enctype="multipart/form-data">
				<form:hidden path="id"/>
						<div class="input">
						<label for="input1">商品名称</label>
							<form:input path="name" id="nickname" required="required"/>
						</div>
						<div class="input">
						<label for="input1">单件库存</label>
							<form:input path="singleStock" id="nickname" required="required"/>
						</div>
						<div class="input">
						<label for="input1">单件价格</label>
							<form:input path="singleUnitPrice" id="nickname" required="required"/>
						</div>
						<div class="input">
						<label for="input1">单件优惠</label>
							<form:input path="singleDiscount" id="nickname"/>
						</div>
						<div class="input">
						<label for="input1">整箱库存</label>
							<form:input path="fullStock" id="nickname" required="required"/>
						</div>
						<div class="input">
						<label for="input1">整箱单价</label>
							<form:input path="fullUnitPrice" id="nickname" required="required"/>
						</div>
						<div class="input">
						<label for="input1">整箱优惠</label>
							<form:input path="fullDiscount" id="nickname"/>
						</div>
						<div class="input">
							<label style="font-weight:bold;font-size:15px">当前图片</label>
							<img alt="" src="${baseImgUrl}${model.image}" onclick="reSizePic(this);" onsubmit="return false;" style="width:50px;height:50px;">
							<button id="updatePic" onclick="return checkForm(1);" style="position: relative;">修改图片</button>
						</div>
						<div class="input" id="newPic" style="display: none">
							<label for="input1">主图</label>
							<input id="imagePath" type="file" name="file" /><span style="">&nbsp;&nbsp;标题图片(尺寸width:750;height:360)</span>
						</div>
						<div class="input">
						<label for="input1">状态</label>
						</div>
						<form:select path="status" id="status" >
								<option value="0" <c:if test="${model.status == 0 }">selected="selected"</c:if> >未上架</option>
								<option value="1" <c:if test="${model.status == 1 }">selected="selected"</c:if>>已上架</option>
								<option value="2" <c:if test="${model.status == 2 }">selected="selected"</c:if>>已下架</option>
								<option value="3" <c:if test="${model.status == 3 }">selected="selected"</c:if>>已删除</option>
						</form:select>
						<div class="input">
							<label for="input1">商品描述</label>
						</div>
						<br><br>
					    <form:hidden path="detail" id="detail"/>
					    <br/>
						<script id="editor" type="text/plain" style="width:1024px;height:500px;"></script>
				<div class="submit" style="margin-top: 20px;">
					<input type="submit" value="修改"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<input type="reset" value="取消" class="white" onClick="javascript :history.go(-1);"/>
				</div>
			</form:form>
		</div>
	</div>
</div>	
	
</div>
<script type="text/javascript">
var curPageName = "admin-gftgoods";
changeCurrent();
//实例化编辑器
//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
var ue = UE.getEditor('editor');
var errorMsg = "${errorMsg}";
ue.ready(function() {//编辑器初始化完成再赋值  
	setTimeout(function(){
		// 动态配置插入到编辑器的路径
		var reg = new RegExp('\\"',"");  
	 	var imageUrlPrefixOfProp = getCookie("imageUrlPrefix");
	 	imageUrlPrefixOfProp = imageUrlPrefixOfProp.replace(reg, "").replace(reg, "");
		ue.options.imageUrlPrefix = imageUrlPrefixOfProp;
		ue.options.fileUrlPrefix = imageUrlPrefixOfProp;
		ue.setContent($("#detail").val());
		}, 500);

});
/**
 * @Description 校验form
 */
function checkForm(flg){
	if(null != flg && flg == 1){
		//修改图片
		$("#newPic").show();
		return false;
	}
	var content = getContent();
	var newContent = content.replace(new RegExp("\"","gm"),"\'");
	if(newContent==null||newContent==''){
		myAlert("请填写商品介绍");
		return false;
	}else{
		$("#detail").val(newContent);
	}
	return true;
}
function getContent() {
    var arr = [];
    arr.push(UE.getEditor('editor').getContent());
    return arr.join("\n");
} 
//@Document 删除my97Datepicker里的"快速选择"的dom   @author sushile @Date 2017-07-27
function reloadd( val ){
	if( val == 1){
		WdatePicker({dateFmt:'HH:mm:ss',alwaysUseStartDate:true,isShowClear:false,readOnly:true});
		var bod = $("body").context.documentElement;
		var lastElement = bod.lastElementChild.lastElementChild;
		var firstElement = lastElement.firstChild.contentDocument;
		if( typeof firstElement == 'undefined'){
			$("div:lang(zh-cn)").each(function(i,element){
				if( $(element).find('iframe').length > 0){
					firstElement = element.firstChild.contentDocument
				}
			})
		}
		$(firstElement).find("#dpTitle").next('div').css({'display':'none'}); 
		$(firstElement).find("#dpTime").prev('div').html('');
		$(firstElement).find("#dpTime").css({'position':'relative'});
		$(firstElement).find("#dpTime").children("div:eq(0)").css({'top':'117px','left':'0px'});
		$(firstElement).find("#dpTime").children("div:eq(1)").css({'top':'70px','left':'0px'});
		$(firstElement).find("#dpTime").children("div:eq(2)").css({'top':'45px','left':'0px'});
	}else if( val == 2){
		var bod = $("body").context.documentElement;
		var lastElement = bod.lastElementChild.lastElementChild;
		var firstElement = lastElement.firstChild.contentDocument;
		$(lastElement).find("iframe").css({'height':'200px'});
		$(firstElement).find("#dpTime").prev('div').css({'display':'inherit'}); 
		WdatePicker({startDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true,readOnly:true})
	}
}
</script>
